package GUI;

import model.*;
import order.*;

import javax.swing.*;

import GUI.MapPanel.TerritoryPanel;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;


public class CreateSpyFrame extends OrderFrame{
	 
	 private CreateSpyFrame createSpyFrame;
	 private JComboBox<TechnologyLevel> sourceBox;
	 private CreateSpy temp;

	 public CreateSpyFrame(TextPanel textPanel,  TerritoryPanel territoryPanel, Map map){
		super(textPanel, territoryPanel, map);
		createSpyFrame = this;

		this.setLayout(new GridLayout(2, 2, 10, 10));	   
		
		this.add(new JLabel("Create a new Spy using:  "));	
	  	sourceBox= new JComboBox<TechnologyLevel>();
	  	for (TechnologyLevel level : TechnologyLevel.values())
	  		if (territory.getTroopAmount(level) > 0)
	  			sourceBox.addItem(level);
		  	
	  	this.add(sourceBox);
	  	this.add(submitButton);
	  	this.add(cancelButton);
	  	submitButton.addActionListener(new submitListener());
	  	cancelButton.addActionListener(new cancelListener(this));
	  	
	  	this.setSize(400, 150);
	  	this.setVisible(true);
	 }
	 

	 class submitListener implements ActionListener{
   
	  public void actionPerformed(ActionEvent arg0) {
		TechnologyLevel source = (TechnologyLevel)sourceBox.getSelectedItem();
		  temp = new CreateSpy(territory, player, source);
	  	 if (temp.checkOrder()){
		  	    textPanel.addHistory(temp);
		  	    temp.executeOrder();
		  	   textPanel.updatePlayerPanel();
				territoryPanel.update();
		     }
	  	 createSpyFrame.dispose();
	}
	 }
	 
}

